using System;
using System.Management;
using System.Net.NetworkInformation;

namespace Catastrophe.Common.SoftLicensing
{
	public class ComputerInfo
	{
		public static string GetCPUInfo()
		{
			return ComputerInfo.GetHardWareInfo("Win32_Processor", "ProcessorId");
		}

		public static string GetBIOSInfo()
		{
			return ComputerInfo.GetHardWareInfo("Win32_BIOS", "SerialNumber");
		}

		public static string GetBaseBoardInfo()
		{
			return ComputerInfo.GetHardWareInfo("Win32_BaseBoard", "SerialNumber");
		}

		public static string GetMACInfo()
		{
			return ComputerInfo.GetHardWareInfo("Win32_BaseBoard", "SerialNumber");
		}

		private static string GetHardWareInfo(string typePath, string key)
		{
			try
			{
				ManagementClass managementClass = new ManagementClass(typePath);
				ManagementObjectCollection instances = managementClass.GetInstances();
				PropertyDataCollection properties = managementClass.Properties;
				foreach (PropertyData item in properties)
				{
					if (!(item.Name == key))
					{
						continue;
					}
					using ManagementObjectCollection.ManagementObjectEnumerator managementObjectEnumerator = instances.GetEnumerator();
					if (managementObjectEnumerator.MoveNext())
					{
						ManagementObject managementObject = (ManagementObject)managementObjectEnumerator.Current;
						return managementObject.Properties[item.Name].Value.ToString();
					}
				}
			}
			catch (Exception ex)
			{
				throw ex;
			}
			return string.Empty;
		}

		public static string GetMacByNetworkInterface()
		{
			try
			{
				NetworkInterface[] allNetworkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
				NetworkInterface[] array = allNetworkInterfaces;
				int num = 0;
				if (num < array.Length)
				{
					NetworkInterface networkInterface = array[num];
					return BitConverter.ToString(networkInterface.GetPhysicalAddress().GetAddressBytes());
				}
			}
			catch (Exception)
			{
			}
			return "00-00-00-00-00-00";
		}
	}
}
